home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / modprolg / mod-prol.lha / Prolog / Examples / utils1.mod < prev   
Text File  |  1992-06-09  |  872b  |  30 lines

  1. structure utils1 =
  2.     struct
  3.       % For each X do Y.
  4.         foreach(X,Y) :-
  5.             call(X),
  6.             do(Y),
  7.             fail.
  8.         foreach(_,_).
  9.         do(Y) :-
  10.             call(Y),!.
  11.       % Read in a sentence, terminated by a '.' and tag
  12.       % each word with Tag.
  13.         get_sentence(Wordlist,Tag) :-
  14.             get0(Char),
  15.             getrest(Char,Wordlist,Tag).
  16.         getrest(46,[],_) :- !.
  17.         getrest(32,Wordlist,Tag) :- !,
  18.             get_sentence(Wordlist,Tag).
  19.         getrest(Letter,[Word|Wordlist],Tag) :-
  20.             getletters(Letter,Letters,Nextchar),
  21.             name(Word,Letters,Tag),
  22.             getrest(Nextchar,Wordlist,Tag).
  23.         getletters(46,[],46) :- !.
  24.         getletters(32,[],32) :- !.
  25.         getletters(Let,[Let|Letters],Nextchar) :-
  26.             get0(Char),
  27.             getletters(Char,Letters,Nextchar).
  28.     end.
  29.  
  30.